package it.polimi.traveldream.web.beans.customer;

import it.polimi.traveldream.ejbclient.dtos.TravelPackageDTO;
import it.polimi.traveldream.ejbclient.eaos.TravelPackageServiceEAO;
import it.polimi.traveldream.utils.enums.PackageType;
import it.polimi.traveldream.web.beans.shared.FacesContextHandler;

import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

@ManagedBean(name="detailCustomerPackage")
@RequestScoped
public class DetailPackageBean {
	@EJB
	private TravelPackageServiceEAO tService;
	@ManagedProperty(value="#{listCustomerTravelPackages.selectedTravelPackage}")
	private TravelPackageDTO travelPackage;
	
	public DetailPackageBean() {
	}
	
	public TravelPackageDTO getTravelPackage() {
		return travelPackage;
	}

	public void setTravelPackage(TravelPackageDTO travelPackage) {
		this.travelPackage = travelPackage;
	}
	
	public String customize() {
		if(travelPackage.getType() == PackageType.PREDEFINED) {
			return "addPackage";
		} else {
			FacesContextHandler.produceFacesMessage(null,FacesContext.getCurrentInstance(),
					FacesMessage.SEVERITY_INFO, "You can customize only predefined packages.");
			return "detailTravelPackage";
		}
	}
	
}
